//
//  XLGSendQueueManagerInternal.h
//  etionCBLogic
//
//  Created by wjxfhxy on 1/15/14.
//  Copyright (c) 2014 GuangZhouXuanWu. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "XLGSendQueueManager.h"

#import "XLGPackFileUp.h"

#import "XLGSendQueueIndex.h"

#import "SocketChannel.h"

#import "XLGSendQueueDBOperation.h"

#import "XLGSendQueuePool.h"

@interface XLGAddSendItem : NSObject
{
    XLGSendQueueManager *_sendQueueManager;
    XLGSendQueueIndex *_mi;
    id _uitarget;
}
@end

@interface XLGSendFileName : NSObject
{
    NSString *_fileName;
    NSString *_fileExt;
}
@property(nonatomic, retain) NSString *fileName;
@property(nonatomic, retain) NSString *fileExt;
@end

@interface XLGSendItem () <CSocketChannelDelegate>
{
    XLGSendQueueManager *_sendQueueManager;

    XLGSendQueueIndex *_mi;
    XLGSendBytesType _sbtype;
    NSUInteger _nHadsendedbytes;
    NSUInteger _nTotalwillsendbytes;
    XMSDataOperationManager *_managerService;

    NSMutableArray *_arSendItemDelegate;

    BOOL _bWillenterforceground;
    
    BOOL _forceTerminal;
}

- (void)setForceTerminal:(BOOL)forceTerminal;

- (id)initWhthSendQueueManager:(XLGSendQueueManager *)sendQueueManager messageinstance:(XLGSendQueueIndex *)mi;

- (void)suspendSendItem:(BOOL)enterForceground;

@end


@interface XLGSendQueueManager ()
{
    NSMutableArray *_arSenditemanager;

    NSTimeInterval _enterbgtimeinterval;

    BOOL _bRunloop;
    NSThread *_scanThread;
    NSCondition *_scanCondition;
    NSTimeInterval _currentscaninterval;
    
    XLGSendQueuePool *_pool;

    BOOL _bSuspending;

@public
    XLGSendQueueDBOperation *_commonindex;
    NSMutableArray *_arQueue;
    XMSDispatchQueueWrapper *_arraylockqueue;
    XMSDispatchQueueWrapper *_uilockqueue;
}

- (void)exchangeSendItemStatus:(XLGSendItem *)senditem;

- (void)exchangeAllSendItemStatus:(XLGSendItemStatusType)oldtype toNewType:(XLGSendItemStatusType)newtype;

- (void)openScanThread;

@end

@interface XLGSendQueueIndex (XLGSendQueueIndexInternal)

+ (XLGSendQueueIndex*)sendQueueIndexWithSendQueueIndex:(XLGSendQueueIndex*)sendQueueIndex;

@end
